<template>
  <div class="app-container">
    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="nurseList" element-loading-text="正在查询中。。。" fit highlight-current-row>
      <el-table-column align="center" width="100px" label="用户ID" prop="id" sortable/>

      <el-table-column align="center" label="工号" prop="jobNumber"/>

      <el-table-column align="center" label="用户名" prop="name"/>

      <el-table-column align="center" label="性别" prop="sex">
        <template slot-scope="scope">
          <el-tag >{{ genderDic[scope.row.sex] }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column align="center" label="手机号码" prop="phone"/>

      <el-table-column align="center" label="科室部门" prop="department"/>

      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status"
            size="mini"
            type="primary"
            disabled
            @click="verity(scope.$index, scope.row)">已验证</el-button>
          <el-button
            v-else
            size="mini"
            type="primary"
            @click="verity(scope.$index, scope.row)">验证</el-button>
        </template>
      </el-table-column>

    </el-table>
  </div>
</template>

<script>
import { addNurse, getAllNurse, getNurse, verifyNurse } from '@/api/nurse'
import { MessageBox } from 'element-ui'

export default {
  name: 'Nurse',
  data() {
    return {
      nurse: {
        name: '姚娟',
        userId: 1,
        jobNumber: '111111',
        phone: '1234567890',
        department: '儿科',
        sex: 0
      },
      nurseList: [],
      listLoading: false,
      statusDic: ['可用', '禁用'],
      genderDic: ['男', '女', '未知']
    }
  },
  created() {
    this.init()
  },
  methods: {
    addtest() {
      addNurse(this.nurse).then(response => {
        console.log(response.data)
        this.$notify.success({
          title: '成功',
          message: '创建成功'
        })
        this.$router.push({ path: '/nurses/list' })
      }).catch(response => {
        MessageBox.alert('业务错误：' + response.data.errmsg, '警告', {
          confirmButtonText: '确定',
          type: 'error'
        })
      })
    },

    init() {
      getAllNurse().then(response => {
        this.nurseList = response.data.data
        console.log(this.nurseList)
      })
    },

    getDetail() {
      getNurse({
        id: '1'
      }).then(response => {
        console.log(response)
      })
    },
    verity(index, nurse) {
      console.log(nurse)
      verifyNurse(nurse).then(response => {
        console.log(response.data)
        this.nurseList[index] = response.data.data
      })
    }
  }
}
</script>

<style scoped>

</style>
